package main

import (
	"account/service"
	"context"
	"flag"
	"fmt"
	"log"
	"net"

	useraccount "account/config"
	log2 "account/log"
	"google.golang.org/grpc"
)

var port = flag.Int("port", 16011, "The server registerPort")

func main() {
	flag.Parse()
	lis, err := net.Listen("tcp", fmt.Sprintf("account:%d", *port))
	if err != nil {
		writeLog, err2 := log2.WriteLog(context.Background(), "account", "GRPC server", "account GRPC server", "Error", err.Error())
		if writeLog == 200 {
			fmt.Println("成功写入日志")
		}
		if err2 != nil {
			fmt.Println("写入日志失败")
		}
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	useraccount.RegisterUserServerServer(s, &service.UserPower{})
	useraccount.RegisterAdminServerServer(s, &service.AdminPower{})
	log.Printf("server listening at %v", lis.Addr())
	if err := s.Serve(lis); err != nil {
		writeLog, err2 := log2.WriteLog(context.Background(), "account", "GRPC server", "account GRPC server", "Error", err.Error())
		if writeLog == 200 {
			fmt.Println("成功写入日志")
		}
		if err2 != nil {
			fmt.Println("写入日志失败")
		}
		log.Fatalf("failed to serve: %v", err)
	}
}
